<%@ page language = "java" contentType="text/html; charset=UTF-8" %>
<%@ page import="com.mapinfo.mapj.*" %>
<%@ page import="com.creawor.imei.base.*" %>
<%@ page import="java.util.*" %>

<%

	
	String hall=request.getParameter("hall");
	if (hall==null) hall=(String)request.getSession().getAttribute("hall");
	

	Common_qry_QueryMap query_map0 = new Common_qry_QueryMap();
	//将service_hall写入session
	if (hall!=null) 
	{
	 session.setAttribute("hall",hall);
	 
     String sql="select * from v_service_hall where service_hall_code ='"+hall+"'";
     java.util.ArrayList sl = query_map0.findAll_sql(sql,10);
     
     //System.out.println(">>>>>>>>>>>>>>>");
   
	 //System.out.println(query_map0.totalrow);
	
     Iterator it=sl.iterator();
   
     while (it.hasNext())
	 {
      HashMap hm=(HashMap)it.next();
        session.setAttribute("hall_name",(String)hm.get("service_hall_name" ));
        session.setAttribute("area",(String)hm.get("county_code" ));
      }
	}
	else{
	    session.setAttribute("hall",null);
	    session.setAttribute("hall_name",null);
	}
%>
<%
//3个参数:
	/** 
	1. view
	2. column
	3. iconColor
	*/
String view=request.getParameter("view");
String column=request.getParameter("column");
String iconColor=request.getParameter("iconColor");
if(iconColor==null||"".equals(iconColor))
{
	iconColor ="red";
}

/////////////////////////////////////
	String area=request.getParameter("area");
	if(area==null) area=(String)request.getSession().getAttribute("area");
	
	//将行政区写入session
    //area=(String)request.getSession().getAttribute("area");
  if(area==null) {
     area="HZ";
     session.setAttribute("area","HZ");
	 session.setAttribute("area_name","惠州市");
  }
  else
  {
     Common_qry_QueryMap query_map = new Common_qry_QueryMap();

     String sql="select * from t_area where area_code ='"+area+"'";
     java.util.ArrayList sl = query_map.findAll_sql(sql);
     Iterator it=sl.iterator();
     while (it.hasNext())
	 {
      HashMap hm=(HashMap)it.next();
   
     
      session.setAttribute("area",area);
      session.setAttribute("area_name",(String)hm.get("area_name" ));
     }
   }





%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
	<%@ include file="googlemap_include.jsp"%>
    <script type="text/javascript">

function TextualZoomControl() {
    }
    TextualZoomControl.prototype = new GControl();


    TextualZoomControl.prototype.initialize = function(map) {
      var container = document.createElement("div");

      var zoomInDiv = document.createElement("div");
	  //zoomInDiv.style.font="small Arial 1em";

      this.setButtonStyle_(zoomInDiv);
      container.appendChild(zoomInDiv);
      zoomInDiv.appendChild(document.createTextNode("地图"));
      GEvent.addDomListener(zoomInDiv, "click", function() {
	 	map.setMapType(G_NORMAL_MAP);
        
      });

      var zoomOutDiv = document.createElement("div");
      this.setButtonStyle_(zoomOutDiv);
      container.appendChild(zoomOutDiv);
      zoomOutDiv.appendChild(document.createTextNode("地形地图"));
      GEvent.addDomListener(zoomOutDiv, "click", function() {
	  	map.setMapType(G_PHYSICAL_MAP);
        
      });

      map.getContainer().appendChild(container);
      return container;
    }

    TextualZoomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
    }

    TextualZoomControl.prototype.setButtonStyle_ = function(button) {
      button.style.textDecoration = "underline";
      button.style.color = "#0000cc";
      button.style.backgroundColor = "white";
      button.style.font = "small-caps   9pt   serif";
	 
      button.style.border = "1px solid black";
      button.style.padding = "2px";
      button.style.marginBottom = "3px";
      button.style.textAlign = "center";
      button.style.width = "5em";
      button.style.cursor = "pointer";
    }

	
	var map = null;
    var geocoder = null;
	var baseIcon=null;
    function initialize() {
      if (GBrowserIsCompatible()) {
	  
         map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl()); 
		map.addControl(new GOverviewMapControl());
     	map.enableDoubleClickZoom();
     	map.enableScrollWheelZoom();
     	map.enableContinuousZoom(); //
		map.setMapType(G_PHYSICAL_MAP);
		//shao guan is (24.996016,113.59314).
        //map.setCenter(new GLatLng(24.816498,113.597088), 14);
		//huizhou is (22.87965466225453,114.5438003540039)
		map.setCenter(new GLatLng(24.996016,113.59314), 10);
		map.addControl(new TextualZoomControl());

		baseIcon = new GIcon();
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 24);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);
		var point =null;
<%
String imagename="column_"+iconColor+"_";
// get the datas from database;
Common_qry_QueryMap query_map = new Common_qry_QueryMap();
String sql = "select * from "+view;
ArrayList list = query_map0.findAll(sql);
//System.out.println("record count="+list.size());
Iterator it=list.iterator();
ArrayList columns = new ArrayList();  
if(it!=null) 
{
     while (it.hasNext())
	 {
      	Map map=(HashMap)it.next();
        /**
		获取county_name
		*/
		//System.out.println(map);
		//System.out.println("column="+column+","+map.containsKey(column));
		if(map.containsKey(column))
		{
			columns.add(Double.valueOf((String)map.get(column)) );
			
		}
      
	}
	if(columns.size()>0)
	{
		Double max = (Double)Collections.max(columns);
		double maxValue = max.doubleValue();
		//再次循环
		for (Iterator iterator = list.iterator(); iterator.hasNext();) 
		{
			Map map=(HashMap)iterator.next();
			/**
			获取x,y,county_name
			*/
			if(null==map.get("y")||null==map.get("x")||"".equals(map.get("y"))||"".equals(map.get("x")))
			{
				continue;
			}
			if(map.containsKey(column))
			{
				
				String object = (String) map.get(column);
				double value = Double.valueOf(object).doubleValue();
				double percent = value/maxValue;
				//System.out.println("maxValue="+maxValue+",percent="+percent);
				out.print("point = new GLatLng("+map.get("y")+","+map.get("x")+");");
				if(percent==1.0)
				{
					out.print("baseIcon.iconSize = new GSize(15, 45);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+45+".png','"+object+"'));");
				}
				else if(percent>=0.875&&percent<1)
				{
					out.print("baseIcon.iconSize = new GSize(15, 35);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+35+".png','"+object+"'));");
				}
				else if(percent>=0.75&&percent<0.875)
				{
					out.print("baseIcon.iconSize = new GSize(15, 30);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+30+".png','"+object+"'));");
				}
				else if(percent>=0.625&&percent<0.75)
				{
					out.print("baseIcon.iconSize = new GSize(15, 25);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+25+".png','"+object+"'));");
				}
				else if(percent>=0.5&&percent<0.625)
				{
					out.print("baseIcon.iconSize = new GSize(15, 20);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+20+".png','"+object+"'));");
				}
				else if(percent>=0.375&&percent<0.5)
				{
					out.print("baseIcon.iconSize = new GSize(15, 15);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+15+".png','"+object+"'));");
				}
				else if(percent>=0.25&&percent<0.375)
				{
					out.print("baseIcon.iconSize = new GSize(15, 10);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+10+".png','"+object+"'));");
				}
				else if(percent>=0.125&&percent<0.25)
				{
					out.print("baseIcon.iconSize = new GSize(15, 5);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+5+".png','"+object+"'));");
				}
				else if(percent<0.125)
				{
					out.print("baseIcon.iconSize = new GSize(15, 5);");
					out.print("map.addOverlay(createMarker(point,baseIcon,'"+imagename+5+".png','"+object+"'));");
				}
			}
		}
	}
}
	
%>
		
		  }
    }
	
	function createMarker(point, imageName,html) {
          
          var letteredIcon = new GIcon(baseIcon);
          letteredIcon.image = "http://www.bipub.org/images/GoogleMapsIcons/"+imageName;
		 
          // 设置 GMarkerOptions 对象
          markerOptions = { icon:letteredIcon };
          var marker = new GMarker(point, markerOptions);

          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml("标记  <b>" + html + "</b>");
          });
          return marker;
        }
		
		function createMarker(point, newIcon ,imageName,html) {
          
          var letteredIcon = new GIcon(newIcon);
          letteredIcon.image = "http://www.bipub.org/images/GoogleMapsIcons/"+imageName;
		  
          // 设置 GMarkerOptions 对象
          markerOptions = { icon:letteredIcon };
          var marker = new GMarker(point, markerOptions);

          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml("指标：  <b>" + html + "</b>");
          });
          return marker;
        }
</script>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Map</title>
<style type="text/css">
<!--
.css1 {  font-size: 12pt; color: #FFFFFF}
-->
</style>






<base target="_self">
<link rel="StyleSheet" href="./css/table.css" type="text/css" />

</head>
<body bgcolor="#DFFFDF" link="#000000" vlink="#000000" alink="#000000" scroll='auto'  onLoad="initialize()" onUnload="GUnload()">    










<form action="show_hint.jsp" name='areaform' id='areaform' methold='post' target='_self'>
<input type="hidden"  name="area" id="area" value="<%=area%>">
<input type="hidden"  name="hall" id="hall"  >
</form>
<%@ include file="googlemap_include2.jsp"%>    
<script>
top.stateFrame.location.href='statusbar.htm';
</script>
</body>




</html>